package com.ztools.pc.controller.information;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.information.Student;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.pc.service.information.StudentService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author:一口香菜
 * @Date: 2023/3/19  12:41
 * @Version 1.0
 */
@RestController
@RequestMapping("/information/student")
public class StudentController {

    @Resource
    private StudentService studentService;

    @RequestMapping("/list")
    public Result findList(@RequestBody PageUtil<Student> pageUtil) {
        Page<Student> list = studentService.findList(pageUtil);
        return list != null ? Result.success().data(list) : Result.error();
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Student student) {
        boolean b = studentService.add(student);
        return b ? Result.success("添加成功") : Result.error("添加失败");
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Student student) {
        boolean b = studentService.update(student);
        return b ? Result.success("修改成功") : Result.error("修改失败");
    }

    @RequestMapping("/delete")
    public Result delete(@RequestBody Student student) {
        boolean b = studentService.delete(student);
        return b ? Result.success("删除成功") : Result.error("删除失败");
    }

    @RequestMapping("/findByObject")
    public Result findByObject(@RequestBody Student student) {
        List<Student> list = studentService.findByObject(student);
        return list != null ? Result.success().data(list) : Result.error();
    }

    @RequestMapping("/export")
    public void excel(HttpServletResponse response, @RequestBody Student student) {
        studentService.exportExcel(response, student);
    }
}
